package com.pjb.springbootjjwt.store.storage.fun;

import java.util.HashMap;
import java.util.Map;

public class FunctionUtil {

    private FunctionUtil() {

    }

    public static Map<String, String> parse(String sql) {
        Map<String, String> r = new HashMap<>();
        String[] arr = sql.split(";");
        for (String s : arr) {
            if (s.contains("=")) {
                String[] kv = s.split("=");
                r.put(kv[0].split("\\s+")[1], kv[1]);
            }
            if (s.contains("return")) {
                String v = s.replace("return", "").trim();
                r.put("return", v);
            }
        }
        return r;
    }

    public static String analysis(Map<String, String> map) {
        String z = map.get("return");
        String r;
        while (true) {
            r = map.get(z);
            if (r.contains("'")) {
                return r;
            }
        }
    }

    public static void main(String[] args) {
        String s = "vchar z = 'Hello world,i am mysql'; return z;";
        String r = analysis(parse(s));
        System.out.println(r);
    }
}
